import { useState } from "react";
import { Switch } from "antd";
import { adminAPI } from "../../../apis/user";

/**
 * @desc 禁用状态
 * @author Gaollard
 */
export default function StatusSwitch (props: any) {
  const { record } = props;
  const checked = Number(record.status) === 1;
  const [loading, setLoading] = useState(false);
  return (
    <Switch defaultChecked={checked} loading={loading} onChange={(v) => {
      setLoading(true);
      adminAPI.adminEdit({
        id: record.id,
        username: record.username,
        email: record.email,
        status: v ? 1 : 0
      }).then((res: any) => {
        if (res && res.success) {
          console.log("操作成功");
        }
      }).finally(() => {
        setLoading(false)
      })
    }} />
  )
}